package com.miandian.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.miandian.common.R;
import com.miandian.entities.Time;
import com.miandian.entities.Video;
import com.miandian.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RestController
@RequestMapping("/api/video")
public class VideoController {
    @Autowired
    private VideoService videoService;

    /**
     * 菜单详情
     */
    @GetMapping("/detail")
    public R detail(@RequestParam Integer id){
        QueryWrapper<Video> queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",id);
        Video video = videoService.getOne(queryWrapper);
        return R.success(video);
    }

    @GetMapping("/getList")
    public R getList(@RequestParam Integer current,@RequestParam Integer pageSize){
        Page pageInfo = new Page(current,pageSize);
        LambdaQueryWrapper<Video> queryWrapper = new LambdaQueryWrapper<>();
        videoService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }
    @DeleteMapping("/delete")
    public R delete(@RequestParam List<Integer> ids){
        videoService.removeByIds(ids);
        return R.success("删除成功");
    }
    @PostMapping("/save")
    public R save(@RequestBody Video video){
        videoService.save(video);
        return R.success("新增成功");
    }
    @PutMapping("/update")
    public R update(@RequestBody Video video){
        videoService.updateById(video);
        return R.success("修改成功");
    }
}
